<?php

class SelectDelivererForm extends sfForm
{
  private $query;
  
  public function __construct($defaults = array(), $options = array())
  {
    $this->query = Doctrine_Query::create()
              ->select('d.*')
              ->from('Deliverer d')
              ->innerJoin('d.DelivererCategories dc');
    
    parent::__construct($defaults, $options);
  }
  
  public function hasRecords()
  {
    return $this->query->execute()->count() == 0;
  }
  
  public function configure()
  {
    $widget = new sfWidgetFormDoctrineChoice(array('model' => 'Deliverer', 'label' => 'Wybierz kontrahenta:', 'query' => $this->query));
    $this->setWidget('deliverer_id', $widget);
  }
}